package com.xz.stu.server.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.xz.stu.server.vo.classroom.*;
import com.xz.stu.server.service.ClassroomService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "教室管理")
@RestController
@RequestMapping("/admin-api/school/classroom")
@Validated
public class ClassroomController {

    @Resource
    private ClassroomService classroomService;

    @PostMapping("/create")
    @Operation(summary = "新增教室")
    public CommonResult<Long> createClassroom(@Valid @RequestBody ClassroomCreateReqVO createReqVO) {
        return success(classroomService.createClassroom(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "修改教室")
    public CommonResult<Boolean> updateClassroom(@Valid @RequestBody ClassroomUpdateReqVO updateReqVO) {
        classroomService.updateClassroom(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除教室")
    public CommonResult<Boolean> deleteClassroom(@PathVariable List<Long> id) {
        classroomService.deleteClassroom(id);
        return success(true);
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "获取教室详情")
    public CommonResult<ClassroomRespVO> getClassroom(@PathVariable Long id) {
        return success(classroomService.getClassroom(id));
    }

    @GetMapping("/list")
    @Operation(summary = "获得教室列表")
    public CommonResult<List<ClassroomRespVO>> getClassroomList(@Valid ClassroomListReqVO listReqVO) {
        return success(classroomService.getClassroomList(listReqVO));
    }

    @GetMapping("/listPage")
    @Operation(summary = "获得教室列表-分页")
    public CommonResult<PageResult<ClassroomRespVO>> getClassroomListPage(@Valid ClassroomListPageReqVO listReqVO) {
        return success(classroomService.getClassroomListPage(listReqVO));
    }
}
